package org.opensourcedea.gui.menu;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.opensourcedea.gui.deaproblem.Navigation;


public class OSDEA_Menu {
	
	  Menu menuBar, fileMenu, toolMenu, helpMenu;
	  MenuItem fileMenuHeader, toolMenuHeader, helpMenuHeader;
	  MenuItem fileNewItem, fileOpenItem, fileSaveItem, fileExitItem, toolImportItem, toolExportItem, helpGetHelpItem, helpAboutItem;
	  Image newImage, openImage, saveImage, exitImage, importImage, exportImage, helpImage;
	  Shell shell;
	  Display display;
	  Navigation navigation;
	
	
	public OSDEA_Menu(Shell parentShell, Display parentdisplay, Navigation parentNavigation) {
		shell = parentShell;
		display = parentdisplay;
		navigation = parentNavigation;
	}
	
	
	public Menu getMenu(Shell shell) {
		
		Menu menuBar = new Menu(shell, SWT.BAR);
		
	    menuBar = new Menu(shell, SWT.BAR);
	    
	    fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
	    fileMenuHeader.setText("&File");

	    fileMenu = new Menu(shell, SWT.DROP_DOWN);
	    fileMenuHeader.setMenu(fileMenu);
	    
	    fileNewItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileNewItem.setText("&New\tCtrl+N");
	    fileNewItem.setAccelerator(SWT.CTRL + 'N');
	    newImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("page_white.png"));
	    fileNewItem.setImage(newImage);
	    
	    fileOpenItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileOpenItem.setText("&Open\tCtrl+O");
	    fileOpenItem.setAccelerator(SWT.CTRL + 'O');
	    openImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("folder.png"));
	    fileOpenItem.setImage(openImage);
	    
	    fileSaveItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileSaveItem.setText("&Save\tCtrl+S");
	    fileSaveItem.setAccelerator(SWT.CTRL + 'S');
	    saveImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("disk.png"));
	    fileSaveItem.setImage(saveImage);

	    fileExitItem = new MenuItem(fileMenu, SWT.PUSH);
	    fileExitItem.setText("&Exit\tAlt+F4");
	    fileExitItem.setAccelerator(SWT.ALT + SWT.F4);
	    exitImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("cross.png"));
	    fileExitItem.setImage(exitImage);
	    
	    
	    toolMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
	    toolMenuHeader.setText("&Tools");
	    
	    toolMenu = new Menu(shell, SWT.DROP_DOWN);
	    toolMenuHeader.setMenu(toolMenu);
	    
	    toolImportItem = new MenuItem(toolMenu, SWT.PUSH);
	    toolImportItem.setText("Import Data");
	    importImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("page_white_put.png"));
	    toolImportItem.setImage(importImage);
	    
	    toolExportItem = new MenuItem(toolMenu, SWT.PUSH);
	    toolExportItem.setText("Export Data");
	    exportImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("page_white_get.png"));
	    toolExportItem.setImage(exportImage);
	    
	    
	    
	    helpMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
	    helpMenuHeader.setText("&Help");

	    helpMenu = new Menu(shell, SWT.DROP_DOWN);
	    helpMenuHeader.setMenu(helpMenu);

	    helpGetHelpItem = new MenuItem(helpMenu, SWT.PUSH);
	    helpGetHelpItem.setText("&Get Help");
	    helpImage = new Image(shell.getDisplay(), this.getClass().getResourceAsStream("help.png"));
	    helpGetHelpItem.setImage(helpImage);
	    
	    helpAboutItem = new MenuItem(helpMenu, SWT.PUSH);
	    helpAboutItem.setText("&About");
	    
	    
	    
	    fileNewItem.addSelectionListener(new FileNewItemListener());
	    fileNewItem.addSelectionListener(new FileOpenItemListener());
	    fileSaveItem.addSelectionListener(new FileSaveItemListener(navigation));
	    fileExitItem.addSelectionListener(new FileExitItemListener(shell, display));
	    toolImportItem.addSelectionListener(new ToolImportItemListener());
	    toolExportItem.addSelectionListener(new ToolExportItemListener());
	    helpGetHelpItem.addSelectionListener(new HelpGetHelpItemListener(navigation));
	    helpAboutItem.addSelectionListener(new HelpAboutItemListener(shell));

	    
	    saveImage.dispose();
	    helpImage.dispose();
	    
	    return menuBar;
	    
	}

	
}
